package hndx.AutoTestWeb.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import hndx.AutoTestWeb.service.MainService;


@Controller
//@RequestMapping(value = "/api") 
public class mainControll {
	
	@Autowired
	MainService mainSrv;
	
	@RequestMapping(value = "/index",method = {RequestMethod.GET,RequestMethod.POST})
	public String index(Model model) {
		//model.addAttribute("msg","helloword!!");
		model.addAttribute("curDate",(new Date()).toString());
		model.addAttribute("doState",mainSrv.getStateStr());
		model.addAttribute("disableState",mainSrv.doState == MainService.RunState.DOING ? "true":"false");
		model.addAttribute("path", mainSrv.getCurPath());
		model.addAttribute("fileList", mainSrv.getResultFiles());
		return "index";
	}
	
	@RequestMapping(value = "/autoTest",method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public void autoTest(HttpServletRequest request,HttpServletResponse response) {
		//model.addAttribute("msg","helloword!!");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		String ret = mainSrv.runAutoTest(response);
		
		System.out.println("巡检输出结果：{"+ret+"}");
		//return ret;
	}
}
